<?php 
require 'db.php';
$strsql = "select * from student left join major on student.major =  major.Id";

$result = mysqli_query($link, $strsql);
$data = mysqli_fetch_all($result);

mysqli_free_result($result);
mysqli_close($link);

?>
<!DOCTYPE html>
<html>
<head>
<title>数据库</title>
<script>
	function edit(id){
		window.location.href="edit.php?id="+id;
	}
	function del(node){
		var td = node.parentNode.parentNode.cells[0];
		var id = td.innerHTML;
		window.location.href="delete.php?id="+id
	}
</script>
</head>
<body>
<a href="new.php">新建数据</a>
    <table>
    	<tr>
    		<th>序号</th>
    		<th>姓名</th>
    		<th>学号</th>
    		<th>学科</th>
    		<th>专业</th>
    		<th>操作</th>
    	</tr>
    	<?php 
    	foreach ($data as $key => $value){
    	?>
    	<tr>
    		<td><?= $value[0]?></td>
    		<td><?= $value[1]?></td>
    		<td><?= $value[2]?></td>
    		<td><?= $value[3]?></td>
    		<td><?= $value[6]?></td>
    		<td>
    		    <a href="edit.php?id=<?=$value[0]?>">编辑1</a>
    			<a href="javascript:;" onclick="edit(<?=$value[0]?>)">编辑2</a>
    			<a href="javascript:;" onclick="del(this)">删除</a>
    		</td>
    	</tr>
    	<?php 
    	}?>
    </table>
</body>
</html>